import request from "@/utils/request";

// 分类列表
export function get_category_list(data) {
  return request({
    url: "/nav/categories/list",
    method: "get",
    data,
  });
}

// 创建分类
export function create_category(data) {
  return request({
    url: "/nav/categories/create",
    method: "post",
    data,
  });
}
// 资源列表
export function get_link_list(data) {
  return request({
    url: "/nav/data/",
    method: "get",
    data,
  });
}

// 新增资源
export function create_link(data) {
  return request({
    url: "/nav/",
    method: "post",
    data,
  });
}

// 搜索资源

// 查询指定分类下的数据
export function get_select_category_data(category_id, nav_title) {
  let url = "/nav/data";
  const params = [];

  if (category_id) {
    params.push(`category=${category_id}`);
  }
  if (nav_title) {
    params.push(`nav_title=${encodeURIComponent(nav_title)}`);
  }
  if (params.length > 0) {
    url += "?" + params.join("&");
  }

  return request({
    url,
    method: "get",
  });
}
// 删除分类
export function delete_category(id) {
  return request({
    url: `/nav/categories/${id}/`,
    method: "delete",
  });
}

// 删除资源
export function delete_link(id) {
  return request({
    url: `/nav/items/${id}/`,
    method: "delete",
  });
}
// 创建商户登录账号密码
export function create_login_info(data) {
  return request({
    url: "/nav/create/company",
    method: "post",
    data,
  });
}

// 获取商户登录账号密码
export function get_login_info(nav_id) {
  return request({
    url: `/nav/company/list?nav_id=${nav_id}`,
    method: "get",
  });
}
